#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 5e5 + 10;

int k, n;
int p[N];

priority_queue<int, vector<int>, greater<int>> heap;

int main() {
#ifdef LOCAL
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif
    cin >> n >> k;
    for (int i = 1 ; i <= n; i++) cin >> p[i];

    for (int i = 1; i <= k; i++) {
        heap.push(p[i]);
    }

    cout << heap.top() << endl;
    for (int i = k+1; i <= n; i++) {
        int tp = heap.top();
        if (p[i] > tp) {
            heap.pop();
            heap.push(p[i]);
        }
        cout << heap.top() << endl;
    }
    return 0;
}
